package io.renren.modules.nuaa.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.constant.Constant;
import io.renren.modules.nuaa.dao.TCategoryDao;
import io.renren.modules.nuaa.dto.TCategoryDTO;
import io.renren.modules.nuaa.entity.TCategoryEntity;
import io.renren.modules.nuaa.service.TCategoryService;
import io.renren.modules.security.user.SecurityUser;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 文章分类
 *
 * @author whc 15953295779@126.com
 * @since 3.0 2023-10-31
 */
@Service
public class TCategoryServiceImpl extends CrudServiceImpl<TCategoryDao, TCategoryEntity, TCategoryDTO> implements TCategoryService {

    @Override
    public QueryWrapper<TCategoryEntity> getWrapper(Map<String, Object> params){
        QueryWrapper<TCategoryEntity> wrapper = new QueryWrapper<>();

        String categoryName = (String) params.get("categoryName");

        if(StringUtils.isNotBlank(categoryName)){
            wrapper.like("category_name",categoryName);
        }

        return wrapper;
    }


    @Override
    public TCategoryEntity queryByName(String categoryName) {

        TCategoryEntity tCategoryEntity = baseDao.selectOne(new QueryWrapper<TCategoryEntity>().eq("category_name", categoryName).last("limit 1"));

            return tCategoryEntity;
    }
}